package string.leetcode_830;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Solution {
    public static void main(String[] args) {
        String s = "abcdddeeeeaabbbcd";
        largeGroupPositions(s);
    }

    public static List<List<Integer>> largeGroupPositions(String s) {
        List<List<Integer>> res = new ArrayList<>();
        for (int i = 0; i < s.length(); i++) {
            //记录相同字符出现次数
            int count = 0;
            while (i + count < s.length() && s.charAt(i) == s.charAt(i + count)) {
                count++;
            }
            //如果出现次数大于3，添加到集合中
            if (count >= 3) {
                res.add(Arrays.asList(i, i + count - 1));
            }
            i = i + count - 1;
        }
        return res;
    }
}
